#include<iostream>
using namespace std;
#include<vector>
void perm(int now, vector<int>& v, int n)
{
	if (now == n - 1)
	{
		for (auto i : v)
		{
			cout << i << ' ';
		}
		cout << endl;
	}
	else
	{
		int j = now;
		for (j; j < n; j++)
		{
			swap(v[j], v[now]);
			perm(now + 1, v, n);
			swap(v[j], v[now]);

		}
	}
}
void permutaions1(int n)
{
	vector<int> v;
	v.resize(n);
	int i = 0;
	for (i; i < n; i++)
		v[i] = i + 1;
	perm(0,v,n);
}
int main()
{
	int n;
	cin >> n;
	permutaions1(n);
}